//
//  ReadCell.m
//  SmileRead
//
//  Created by dllo on 15/8/24.
//  Copyright (c) 2015年 JIZ. All rights reserved.
//

#import "ReadCell.h"
#import "ReadModel.h"
#import "Path.h"

@interface ReadCell ()

@property (nonatomic, retain) UILabel *titleLabel;

@property (nonatomic, retain) UIImageView *titleImage;

@property (nonatomic, retain) UILabel *contentLabel;

@end

@implementation ReadCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10 * widthFit, 10 * heightFit, self.contentView.frame.size.width, 50 * heightFit)];
        self.titleLabel.numberOfLines = 0;
        self.titleLabel.font = [UIFont systemFontOfSize:18];
       // self.titleLabel.backgroundColor = [UIColor cyanColor];
        [self.contentView addSubview:self.titleLabel];
        [_titleLabel release];
        
        
        self.titleImage = [[UIImageView alloc] initWithFrame:CGRectMake(10 * widthFit, 60 * heightFit, self.frame.size.width / 3 * 2 - 20 * widthFit, 80 * heightFit)];
        self.titleImage.backgroundColor = [UIColor greenColor];
        [self.contentView addSubview:self.titleImage];
        [_titleImage release];
        
        self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width / 3 * 2 * widthFit, 60 * heightFit, self.frame.size.width / 3, 80 * heightFit)];
        //self.contentLabel.backgroundColor = [UIColor redColor];
        self.contentLabel.font = [UIFont systemFontOfSize:15];
        self.contentLabel.numberOfLines = 0;
        [self.contentView addSubview:self.contentLabel];
        [_contentLabel release];
        
        
    }
    return self;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.titleLabel.frame = CGRectMake(10 * widthFit, 10 * heightFit, self.contentView.frame.size.width - 20 * widthFit, 50 * heightFit);
    self.titleLabel.numberOfLines = 0;
    
    self.titleImage.frame = CGRectMake(10 * widthFit, 60 * heightFit, self.frame.size.width / 3 * 2 - 90 * widthFit, 80 * heightFit);
    
    self.contentLabel.frame = CGRectMake(self.frame.size.width / 3 * 2 - 70 * widthFit, 60 * heightFit, self.frame.size.width / 3 + 60 * widthFit, 80 * heightFit);
}

- (void)setModel:(ReadModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
        
        self.titleLabel.text = _model.title;
        [Path pathWithImageView:self.titleImage URLString:_model.coverimg];
        self.contentLabel.text = _model.content;
        self.contentLabel.textColor = [UIColor grayColor];
    }
}


// 接受数据, 并设置高亮
- (void)receiveWithModel:(ReadModel *)model text:(NSString *)text
{
    self.titleLabel.attributedText = [Path lightWithTitle:model.title text:text];
}

- (void)dealloc
{
    [_titleImage release];
    [_titleLabel release];
    [_contentLabel release];
    [super dealloc];
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
